package org.devio.secondlevelmenu.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import org.devio.secondlevelmenu.R;
import org.devio.secondlevelmenu.bean.VipShareFirstLebalBean;
import org.devio.secondlevelmenu.bean.VipShareSecondLeftLebalBean;

import java.util.ArrayList;
import java.util.List;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class LabelOneRecyclerViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private Context mContext;
    private List<VipShareFirstLebalBean> mDatas = new ArrayList<>();
    private onItemClick onItemClick;

    public void setOnItemClick(LabelOneRecyclerViewAdapter.onItemClick onItemClick) {
        this.onItemClick = onItemClick;
    }

    public interface onItemClick {
        void onItemClick( VipShareFirstLebalBean bean);
    }

    public LabelOneRecyclerViewAdapter(Context context) {
        mContext = context;
    }


    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View itemView = LayoutInflater.from(mContext).inflate(R.layout.level1menu_item_layout, parent, false);
        return new MyViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        if (mDatas == null && position >= mDatas.size()) return;
        MyViewHolder normalHolder = (MyViewHolder) holder;
        normalHolder.mTV.setText(mDatas.get(position).getTxt());
        normalHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (onItemClick != null) onItemClick.onItemClick(mDatas.get(position));
            }
        });
        if (mDatas.get(position).isSelected){
            normalHolder.mTV.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
            //                normalHolder.mImg.setImageResource(?);

        }else {
            //                normalHolder.mImg.setImageResource(?);
            normalHolder.mTV.setTextColor(Color.parseColor("#FF3F3F3F"));

        }

    }


    public void setData(List<VipShareFirstLebalBean> mDatas) {
        this.mDatas.clear();
        this.mDatas.addAll(mDatas);
        notifyDataSetChanged();
    }

    @Override
    public int getItemCount() {
        return mDatas.size();
    }

    public class MyViewHolder extends RecyclerView.ViewHolder {


        public TextView mTV;
        public ImageView mImg;

        public MyViewHolder(View itemView) {
            super(itemView);
            mTV = itemView.findViewById(R.id.level1_item_tv);
            mImg = itemView.findViewById(R.id.level1_item_iv);

        }

    }
}

